package praktikum_2_ylesanded.testid;

import praktikum_2_ylesanded.ylesanne_1.DynamicArray;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: Jaan Sepp and Martti Elias
 * Date: 19.10.11
 * Time: 20:14
 */
public class DynamicArrayTest extends junit.framework.TestCase {

  DynamicArray dynamicArray = new DynamicArray();

  public void testAddAndLen() throws Exception {
    assertEquals(1, dynamicArray.getDynamicArray().length);
    assertEquals(0, dynamicArray.len());

    dynamicArray.add(100);
    assertEquals(2, dynamicArray.getDynamicArray().length);
    assertEquals(1, dynamicArray.len());

    dynamicArray.add(25);
    assertEquals(4, dynamicArray.getDynamicArray().length);
    assertEquals(2, dynamicArray.len());

    dynamicArray.add(60);
    assertEquals(4, dynamicArray.getDynamicArray().length);
    assertEquals(3, dynamicArray.len());

    dynamicArray.add(555);
    assertEquals(8, dynamicArray.getDynamicArray().length);
    assertEquals(4, dynamicArray.len());

    dynamicArray.add(2500);
    assertEquals(8, dynamicArray.getDynamicArray().length);
    assertEquals(5, dynamicArray.len());

    dynamicArray.add(6000);
    assertEquals(8, dynamicArray.getDynamicArray().length);
    assertEquals(6, dynamicArray.len());
  }

  public void testRem() {
    dynamicArray.addAll(new int[] {10, 20, 30, 40, 50, 60});

    assertEquals(8, dynamicArray.getDynamicArray().length);
    assertEquals(60, dynamicArray.rem());
    assertEquals(8, dynamicArray.getDynamicArray().length);

    assertEquals(50, dynamicArray.rem());
    assertEquals(8, dynamicArray.getDynamicArray().length);

    assertEquals(40, dynamicArray.rem());
    assertEquals(8, dynamicArray.getDynamicArray().length);

    assertEquals(30, dynamicArray.rem());
    assertEquals(4, dynamicArray.getDynamicArray().length);

    assertEquals(20, dynamicArray.rem());
    assertEquals(2, dynamicArray.getDynamicArray().length);

    assertEquals(10, dynamicArray.rem());
    assertEquals(1, dynamicArray.getDynamicArray().length);
  }

  public void testGet() {
    dynamicArray.addAll(new int[] {10, 20, 30, 40, 50, 60});

    assertEquals(40, dynamicArray.get(3));
    assertEquals(60, dynamicArray.get(5));
    assertEquals(10, dynamicArray.get(0));
    assertEquals(-1, dynamicArray.get(20));
    assertEquals(-1, dynamicArray.get(-2));
  }

  public void testPut() {
    dynamicArray.put(60, 0);
    assertEquals(0, dynamicArray.get(0));
    dynamicArray.add(60);
    assertEquals(60, dynamicArray.get(0));
    dynamicArray.put(120, 0);
    assertEquals(120, dynamicArray.get(0));

    dynamicArray.addAll(new int[] {10, 20, 30, 40, 50, 60});

    assertEquals(Arrays.toString(new int[]{120, 10, 20, 30, 40, 50, 60, 0}), Arrays.toString(dynamicArray.getDynamicArray()));
  }
}
